package com.glorysoft.wangnianxinpda.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glorysoft.wangnianxinpda.adapter.viewholder.DataBindingBaseViewHolder;
import com.glorysoft.wangnianxinpda.databinding.AdapterMaterialExchangeBinding;
import com.glorysoft.wangnianxinpda.databinding.AdapterMaterialExchangeInfoBinding;
import com.glorysoft.wangnianxinpda.entity.MaterialInfoEntity;

import java.util.List;

/**
 * FileName: MaterialExchangeInfoAdapter
 * Author: XJH
 * Date: 2022/1/21 16:00
 * Description:
 * History:
 */
public class MaterialExchangeInfoAdapter extends BaseQuickAdapter<MaterialInfoEntity.MaterialDescEntity, DataBindingBaseViewHolder> {
    public OnClickListener listener;
    private String mCode;

    public MaterialExchangeInfoAdapter(int layoutResId, @Nullable List<MaterialInfoEntity.MaterialDescEntity> data) {
        super(layoutResId, data);
    }

    public interface OnClickListener {
        void off(MaterialInfoEntity.MaterialDescEntity item,String code);

        void exchange(MaterialInfoEntity.MaterialDescEntity item,String code);
    }

    public void setListener(OnClickListener listener) {
        this.listener = listener;
    }

    public void setCode(String code){
        this.mCode = code;
    }

    @Override
    protected void convert(DataBindingBaseViewHolder helper, MaterialInfoEntity.MaterialDescEntity item) {
        AdapterMaterialExchangeInfoBinding binding = (AdapterMaterialExchangeInfoBinding) helper.getDataBinding();
        binding.setMaterialDescEntity(item);
        binding.btnDown.setOnClickListener(v -> {
            listener.off(item,mCode);
        });
        binding.btnExchange.setOnClickListener(v -> {
            listener.exchange(item,mCode);
        });
        binding.executePendingBindings();
    }

}